<template>
    <div>
        <h3>SubItem组件</h3>
        <p>已知库存数：{{ count }}</p>
        <button @click="subFn">库存-1</button>
        <div>总消费：{{ totalPrice }}</div>
    </div>
</template>

<script>
//辅助函数来映射
import { mapState,mapMutations,mapActions,mapGetters } from 'vuex'

export default{
     data(){
        return{}
     },
     computed:{ 
        ...mapState(['count']),
        ...mapGetters(['totalPrice'])
     },
     methods:{
        ...mapMutations(['subCount']),      //映射 => mutations
        ...mapActions(['asyncSubCount']),   //映射 => actions
        subFn(){
            // this.subCount(1)
            this.asyncSubCount(1)
        }
     }
}
</script>

<style>

</style>